Skip to content

Comments

fix: Unwrap protobuf Value types in CallParticipantState.custom field#1172

Open
antondokusov wants to merge 1 commit intoGetStream:mainfrom
antondokusov:fix-call-participant-custom-field
Open

fix: Unwrap protobuf Value types in CallParticipantState.custom field#1172
antondokusov wants to merge 1 commit intoGetStream:mainfrom
antondokusov:fix-call-participant-custom-field

Conversation

@antondokusov
Copy link

@antondokusov antondokusov commented Feb 4, 2026

🎯 Goal

Fix an issue where CallParticipantState.custom field contains protobuf Value wrapper objects instead of native Dart types. This makes it difficult for developers to access custom participant data, as they need to manually unwrap each Value object to get the actual values.

The protobuf Struct type uses Value wrappers to represent dynamically-typed data, but when converting to the domain model, these should be unwrapped to native Dart types for easier consumption.

🛠 Implementation details

Changed the conversion in SfuParticipantExtension.toDomain() from:

custom: custom.fields,  // Returns PbMap<String, Value>

to:

custom: (custom.toProto3Json() as Map<String, Object?>?) ?? {},

🎨 UI Changes

N/A

🧪 Testing

This change can be tested by:

  1. Joining a call with participants that have custom data fields
  2. Accessing CallParticipantState.custom and verifying that values are native Dart types instead of protobuf Value objects
  3. Verifying that nested structures (maps and lists) are properly unwrapped

Before the fix:

final participant = call.state.value.callParticipants.first;
final customField = participant.custom['custom_field'] as String; // throws "type 'Value' is not a subtype of type 'String' in type cast"

After the fix:

final participant = call.state.value.callParticipants.first;
final customField = participant.custom['custom_field'] as String; // success

☑️Contributor Checklist

General

  • Assigned a person / code owner group (required)
  • Thread with the PR link started in a respective Slack channel (#flutter-team) (required)
  • PR is linked to the GitHub issue it resolves

☑️Reviewer Checklist

  • Sample runs & works
  • UI Changes correct (before & after images)
  • Bugs validated (bugfixes)
  • New feature tested and works
  • All code we touched has new or updated Documentation

Summary by CodeRabbit

  • Bug Fixes
    • Improved serialization of participant custom data to use a safe JSON fallback, preventing null or missing-field issues and ensuring consistent data handling across participants.

@antondokusov antondokusov requested a review from a team as a code owner February 4, 2026 13:21
@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

Replaced serialization of participant custom data in SfuParticipantExtension.toDomain: it now uses custom.toProto3Json() cast to Map<String, Object?>? with a fallback to {} instead of reading custom.fields. No other control flow or functionality changed.

Changes

Cohort / File(s) Summary
SFU Event Mapper
packages/stream_video/lib/src/sfu/data/events/sfu_event_mapper_extensions.dart
Updated SfuParticipantExtension.toDomain to serialize custom using custom.toProto3Json() cast to Map<String, Object?>? with a fallback to {} instead of custom.fields.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A tiny hop, a single line—
I map the fields to JSON fine,
From proto calls the data springs,
A quiet change that gently sings. 🎋

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: unwrapping protobuf Value types in a specific field.
Description check ✅ Passed The description covers all essential sections with clear goal, implementation details, testing steps, and before/after examples.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/stream_video/lib/src/sfu/data/events/sfu_event_mapper_extensions.dart (1)

244-267: ⚠️ Potential issue | 🔴 Critical

Use toProto3Json() instead of writeToJsonMap() for converting protobuf Struct values to native Dart types.

In protobuf 6.0.0, toProto3Json() is the official, documented API for Proto3 JSON serialization and converting Struct/Value types to native Dart equivalents (String, num, bool, List, Map<String, dynamic>). While writeToJsonMap() exists and may work, it's a generic message-to-map encoder and not the intended API for this conversion.

Change line 251 to: custom: custom.toProto3Json() as Map<String, dynamic>,

@antondokusov antondokusov marked this pull request as draft February 4, 2026 14:12
@antondokusov antondokusov force-pushed the fix-call-participant-custom-field branch from 07fded6 to 6fc26c4 Compare February 4, 2026 14:22
@antondokusov antondokusov force-pushed the fix-call-participant-custom-field branch from 6fc26c4 to d747656 Compare February 4, 2026 14:37
@antondokusov antondokusov marked this pull request as ready for review February 4, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant